{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1d86f707",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e89e4f7b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(x):\n",
    "    return x ** 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2ec95e75",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 11\n",
    "tiList,CiList = np.polynomial.legendre.leggauss(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7db351f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 1\n",
    "b = 4\n",
    "xiList = (b - a) / 2 * (tiList - 1) + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "680b6e9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(b - a) / 2 * CiList.dot (f(xiList))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "82f84cfb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.2642411176571153"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * (1 - np.exp(-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "99d659f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6666666666666661"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CiList.dot(f(xiList))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e359145d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
